package com.lijing.InsertSort;

public class Insertion {
    public static void sort(Comparable[] arr){
        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j > 0; j--) {
                if (greater(arr[j-1],arr[j])){
                    exch(arr,j-1,j);
                }else {
                    break;
                }
            }
        }
    }
    private static boolean greater(Comparable v, Comparable w){
        return v.compareTo(w)>0;
    }
    private static void exch(Comparable[] a, int i, int j){
        Comparable temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
